<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width,initial-scale=1,user-scalable=0">
<style type="text/css">
	body, html{font-family:"微软雅黑";}
	#allmap{width: 100%;height: 500px;overflow: hidden;margin:auto;font-family:"微软雅黑";}
</style>		
<title>用户中心</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=2q9aXau4p4lTSfGWZNZmIv9D"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
<script type="text/javascript" src="arr.js"></script>
<style type="text/css">
	#address{height: 30px;width: 220px;border: 1px solid #ff66ff;border-radius:4px;}
	#address:VISITED{
		border: 1px solid #ff66ff;
	}
	.btn{margin-left:10px;height: 30px;width: 80px;border: 1px solid #ff66ff;border-radius:4px;
		background-color: #fff;cursor: pointer;
	}
	.btn:HOVER {
	background-color: rgb(223,232,247);
}
</style>
</head>
<body>
	<div id="allmap" align="center" style="border: 1px solid #ff66ff;"></div><br>
	<div align="center">
		<input type="text" id="address" onkeypress="if(event.keyCode==13) {search();return false;}"><button onclick="search();" class="btn">搜索</button>
		<div id="positionSpan" style="margin-top: 10px;" ></div>
	</div>
</body>
</html>
<script type="text/javascript">
	// 百度地图API功能
	var map = new BMap.Map("allmap");    // 创建Map实例
	map.centerAndZoom(new BMap.Point(114.013958, 22.641592), 12);  // 初始化地图,设置中心点坐标和地图级别
	map.addControl(new BMap.MapTypeControl());   //添加地图类型控件
	map.setCurrentCity("深圳");          // 设置地图显示的城市 此项是必须设置的
	map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
	map.addEventListener("rightclick", function(e){
			var point =new BMap.Point(e.point.lng, e.point.lat);
			mark(point);
		});
	
	var marker;
	
	var point = new BMap.Point(114.002523,22.638119);
	BMap.Convertor.translate(point, 0, function(point){
		mark(point);
	}); //转换坐标  
	
	
	function mark(point)
	{
		map.removeOverlay(marker);
		marker = new BMap.Marker(point);  // 创建标注
		marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
		marker.enableDragging();           //可拖拽
		map.addOverlay(marker);            // 将标注添加到地图中
		marker.addEventListener("dragend", function(e){
			showLocal(e.point);
		});
		showLocal(point);
	}
	
	var localSearch;
	function search(adr)
	{
		 if(localSearch == null)
	        {
	        	var localSearch = new BMap.LocalSearch(map);
	        	localSearch.setSearchCompleteCallback(function (sRet) {
	        			var point = sRet.getPoi(0).point;
	        			mark(point);
	        			//移动到新的地点
	        			map.panTo(point);
	        		});
	        }
		if(adr)
		{
			document.getElementById('address').value = adr;
		}
		var address = document.getElementById('address').value;
		//if(address.indexOf('深圳市') == -1) address = '深圳市'+address;
		localSearch.search(address);
	}
	
	function showLocal(point)
	{
		var html = '当前坐标：lat:'+point.lat+'，lng'+point.lng;
		document.getElementById('positionSpan').innerHTML = html;
	}
	
</script>